//
//  SettingViewController.m
//  TextApplication
//
//  Created by dllo on 16/9/24.
//  Copyright © 2016年 yh. All rights reserved.
//

#import "SettingViewController.h"
#import "TAMacro.h"
#import "SettingTableViewCell.h"
#import "UIImageView+WebCache.h"

#import "SecLoginItems.h"
#import "SecLoginImage.h"

@interface SettingViewController () <UITableViewDataSource, UITableViewDelegate>
@property (nonatomic, strong) UIImageView *backImageView;

@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSArray *firstArr;
@property (nonatomic, strong) UIView *headView;
@property (nonatomic, strong) UIImageView *headImageView;
@property (nonatomic, strong) UIView *footerView;


@end

@implementation SettingViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.firstArr = [NSArray array];
    self.firstArr = @[@"昵称", @"个人介绍", @"手机"];
    [self createView];
    [self createTableView];
}

- (void)createView {
    self.backImageView = [[UIImageView alloc] initWithFrame:self.view.bounds];
    self.backImageView.image = [UIImage imageNamed:@"36"];
    [self.view addSubview:self.backImageView];
    
    UIButton *backButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [backButton setImage:[UIImage imageNamed:@"6"] forState:UIControlStateNormal];
    backButton.frame = CGRectMake(self.view.bounds.size.width - 40, 35, 20, 20);
    [backButton addTarget:self action:@selector(backClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:backButton];
}

- (void)createTableView {
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(30, 100, WIDTH - 60, 270) style:UITableViewStylePlain];
    self.tableView.backgroundColor = [UIColor colorWithRed:0.176 green:0.153 blue:0.157 alpha:1.000];
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.tableView.scrollEnabled = NO;
    self.tableView.alpha = 0.85;
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    [self.view addSubview:self.tableView];
    
    self.headView = [[UIView alloc] initWithFrame:CGRectMake(40, 0, WIDTH - 80, 80)];
    self.headView.backgroundColor = [UIColor colorWithRed:0.176 green:0.153 blue:0.157 alpha:1.000];
    self.tableView.tableHeaderView = self.headView;
    UILabel *textLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 25, 90, 30)];
    textLabel.font = [UIFont systemFontOfSize:13];
    textLabel.text = @"头像";
    textLabel.textColor = [UIColor whiteColor];
    [self.headView addSubview:textLabel];
    
    self.headImageView = [[UIImageView alloc] initWithFrame:CGRectMake(WIDTH - 140, 5, 70, 70)];
    [self.headImageView sd_setImageWithURL:[NSURL URLWithString:self.secItem.user_images.orig]];
    self.headImageView.backgroundColor = [UIColor yellowColor];
    [self.headView addSubview:self.headImageView];
    
    self.footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, 60)];
    self.footerView.backgroundColor = [UIColor colorWithRed:0.176 green:0.153 blue:0.157 alpha:1.000];
    self.tableView.tableFooterView = self.footerView;
    UIButton *footerButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [footerButton setTitle:@"退出" forState:UIControlStateNormal];
    [footerButton setTitleColor:[UIColor colorWithWhite:0.259 alpha:1.000] forState:UIControlStateNormal];
    footerButton.frame = CGRectMake(self.footerView.bounds.size.width / 2 - 110, 20, 220, 30);
    footerButton.titleLabel.textAlignment = 1;
    footerButton.titleLabel.font = [UIFont systemFontOfSize:13];
    footerButton.backgroundColor = [UIColor whiteColor];
    [self.footerView addSubview:footerButton];
    
    [self.tableView registerClass:[SettingTableViewCell class] forCellReuseIdentifier:@"reuse"];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.firstArr.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    SettingTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"reuse"];
    cell.firstLabel.text = self.firstArr[indexPath.row];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.backgroundColor = [UIColor colorWithRed:0.176 green:0.153 blue:0.157 alpha:1.000];
    if (indexPath.row == 0) {
        cell.secLabel.text = self.secItem.nickname;
    } else if (indexPath.row == 1) {
        cell.secLabel.text = self.secItem.profile;
    } else {
        cell.secLabel.text = @"18304232468";
    }
    return cell;
}
- (void)backClick:(UIButton *)button {
    [self dismissViewControllerAnimated:YES completion:nil];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
